import { log, err } from "../../utils/console";
// import { to, toast } from "../../utils/wxapi";
import { GetOredr } from "../../api/order3c";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    nav: [
      { title: "全部订单", status: "" },
      { title: "待接单", status: "NEW" },
      { title: "进行中", status: "PROCESSING" },
      { title: "已完成", status: "FINISHED" },
      { title: "已取消", status: "CANCELED" },
    ],
    navnum: 0,
    page: 1,
    limit: 20,
    list: [],
    conlist: [],
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getlist();
  },
  async getlist() {
    try {
      const { page, limit } = this.data;
      const res = await GetOredr({ page, limit });
      log(res);
      if (res.statusCode === 200) {
        this.setData({ conlist: res.data, list: res.data });
      } else {
        err(res.data);
      }
    } catch (error) {
      err(error);
    }
  },
  navtab(e: any) {
    const { i } = e.currentTarget.dataset;
    this.setData({ navnum: i });
    const { navnum, nav, conlist } = this.data;
    let list = this.filetr(conlist, nav[navnum].status);
    this.setData({ list });
  },
  filetr(arr: any[], status: string | undefined) {
    console.log(arr, status);
    let list = [] as any;
    if (status === "") {
      list = arr;
    } else {
      arr.forEach((e) => {
        if (e.status === status) {
          list.push(e);
        }
      });
    }
    return list;
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
